package persistence;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import persistence.exception.DAOException;
import persistence.util.JdbcUtil;

public class BindingDetailsDAOJdbcImpl extends JdbcDAOBase implements BindingDetailsDAO {
	
	public BindingDetailsDAOJdbcImpl() {
		super();
	}
	@Override
	public BindingDetails find(int id) throws DAOException{
		String sql = "SELECT id, bindeinfos, rueckentext, jahresregister FROM bindedetails WHERE" +
					 " id = ?";
		Connection con = null;
		PreparedStatement prepStmt = null;
		ResultSet rs = null;
		BindingDetails bindingDetails = null;
		
		try {
			con = getConProvider().getConnection();
			prepStmt = con.prepareStatement(sql);
			prepStmt.setInt(1, id);
			rs = prepStmt.executeQuery();			

			if (rs.next()) {
				bindingDetails = new BindingDetails (rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4));
			}
		}
		catch (SQLException se) {
			throw new DAOException("Problem when attempting to find BindingDetails with id: " + id, se);
		}
		finally {
			JdbcUtil.cleanup(con, prepStmt, rs);
		}
		return bindingDetails;
	}

	@Override
	public List<BindingDetails> findAllByTitle() throws DAOException{
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void updateBindingDetails() throws DAOException{
		// TODO Auto-generated method stub

	}

	@Override
	public BindingDetails create() throws DAOException{
		// TODO Auto-generated method stub
		return null;
	}

}
